import { NavigationActions, StackActions } from 'react-navigation';

export default class NavigationUtil {
    static fromHometoPage(page, params) {
        const navigation = NavigationUtil.home_navigation;
        if (!navigation) {
            console.log('NavigationUtil.home_navigation can not be null')
            return;
        }
        navigation.navigate(
            page,
            {
                ...params
            }
        )
    }

    static goBack(props) {
        const { navigation } = props;
        navigation.goBack();
    }

    static resetTo(props, page) {
        const { navigation } = props;
        let resetAction = StackActions.reset({//清空 stack
            index: 0,
            actions: [
                NavigationActions.navigate({ routeName: page })
            ]
        });
        navigation.dispatch(resetAction);
    }
    static navigate(props, page, params) {
        const { navigation } = props;
        navigation.navigate(
            page,
            {
                ...params
            }
        )
    }
}